//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.pss;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.PssProductStockDao;
import com.aidong.model.wills.PssProductStockExt;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.pss.PopProductController;
import java.util.Iterator;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"productStockList"})
public class ProductStockListController extends PopProductController {
    @Resource
    PssProductStockDao pssProductStockDao;

    public ProductStockListController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("pss/productStock/list")).addObject("shopName", this.getTypeList("shopName"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "productCode",required = false) String productCode, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "a.ShopCode", shopCode);
        if(!this.chkNull(productCode)) {
            cd.eq("a.ProductCode", productCode);
        }

        this.pssProductStockDao.getProductStockLst(pg, cd);
        Iterator mv = pg.getResultList().iterator();

        while(mv.hasNext()) {
            PssProductStockExt pss = (PssProductStockExt)mv.next();
            pss.setAmount2(Double.valueOf(pss.getQuantity().doubleValue() * pss.getPurcPrice2().doubleValue()));
        }

        ModelAndView mv1 = new ModelAndView("pss/productstock/_list");
        mv1.addObject("list", pg.getResultList());
        mv1.addObject("shopName", this.getTypeList("shopName"));
        mv1.addObject("productUnit", this.getTypeList("productUnit"));
        mv1.addObject("ProductcodeList", this.getTypeList("ProductcodeList"));
        mv1.addObject("pg", pg);
        return mv1;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "productCode",required = false) String productCode, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, 20000);
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "a.ShopCode", shopCode);
            if(!this.chkNull(productCode)) {
                cd.eq("a.ProductCode", productCode);
            }

            this.pssProductStockDao.getProductStockLst(e, cd);
            ExportXls xls = new ExportXls(response, "商品库存余额", "商品库存余额");
            xls.addHead(new String[]{"门店编号", "门店名称", "商品编码", "商品名称", "单位", "数量", "标准采购价", "金额", "平均采购价", "金额"});
            xls.setWidth(new int[]{10, 25, 10, 25, 10, 10, 10, 10, 10, 10});
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                PssProductStockExt puot = (PssProductStockExt)i$.next();
                puot.setAmount2(Double.valueOf(puot.getQuantity().doubleValue() * puot.getPurcPrice2().doubleValue()));
                xls.addRow(new Object[]{puot.getShopCode(), this.cache.getValue("shopName", puot.getShopCode()), puot.getProductCode(), this.cache.getValue("ProductcodeList", puot.getProductCode()), this.cache.getValue("productUnit", puot.getUnit()), puot.getQuantity(), puot.getPurcPrice1(), puot.getAmount1(), puot.getPurcPrice2(), puot.getAmount2()});
            }

            xls.close();
            this.addUserLog("导出商品库存余额", e.getResultList().size() + "条记录");
        } catch (Exception var9) {
            this.log.error("import", var9);
        }

        return null;
    }
}
